<?php
class Proposal_plan_menu_model extends CI_MODEL
	{
		public function __construct()
			{
				parent::__construct();
				$this->load->database();
			}

		function plan_data_generate($module_id)
			{
				$this->db->select('*');
				$query = $this->db->from('proposal_module_plans');
				$this->db->where('module_id',$module_id);
				$this_db = $this->db;
				//$result_array = $this_db->get()->result_array();
				$plan_count = $this_db->count_all_results();
				
				$this->db->select('plan_video_link,plan_price,plan_description,plan_deliverables');
				$query = $this->db->from('proposal_module_plans');
				$this->db->where('module_id',$module_id);
				$this->db->where('plan_number', '1'); 
				$plan_details_default = $this->db->get()->row_array();
				
				$this->db->select('module_name');
				$query = $this->db->from('proposal_module_details');
				$this->db->where('id',$module_id);
				$module_name_default = $this->db->get()->row_array();
				//$module_type_details = $this->db->get()->result_array();
				
				$result = array("plan_count" => $plan_count);
				$result = array_merge($result, $plan_details_default ,$module_name_default);
				
				
				//var $only_result = 
				
				
				/*$result['title'] = $title;
				$result['url'] = $url;
				$result = json_encode($result);
				echo $result;*/
							
				/*
				//print_r($module_type_details);
				$sql = $this->db->last_query();
				echo($sql."<br/>");
				//exit;
				*/				
				//echo("<pre>");
				//print_r($module_type_details);
				//echo json_encode($module_type_details);
				return $result;//$result = array_merge($array1, $array2);			
			}
			
		function tree_view()
			{
     			$this->db->select('id,parent_id,name');
				$query = $this->db->from('proposal_category_tree');
				$module_type_details = $this->db->group_by('id');
				$module_type_details = $this->db->get()->result();
        		return $module_type_details;
			}
			
		function proposal_view()
			{
     			$this->db->select('id,proposal_name');
				$query = $this->db->from('proposal_client_plans');
				$module_type_details = $this->db->group_by('id');
				$module_type_details = $this->db->get()->result();
        		return $module_type_details;
			}	
			
		function plan_data_update($plan_id)
			{
				$this->db->select('*');
				$query = $this->db->from('proposal_module_plans');
				$this->db->where('plan_number',$plan_id);
				$plan_details = $this->db->get()->row_array();
				//return $this->db->last_query();				
				return ($plan_details);
			}
		function plan_data_save($if_proposal_custom,$proposal_module_id,$proposal_plan_number,$proposal_name,$module_description,$module_deliverables,$custom_field,$custom_field_pos)					
			{
				$max = sizeof($proposal_module_id);				
				for($i = 0; $i < $max;$i++)
					{
						$plan_data = array();
						$plan_data['id'] = $this->db->count_all('proposal_client_plans');
						$plan_data['if_proposal_custom'] = $if_proposal_custom;
						$plan_data['proposal_module_id'] = $proposal_module_id;
						$plan_data['proposal_plan_number'] = $proposal_plan_number;
						$plan_data['proposal_name'] = $proposal_name;
						$plan_data['module_description'] = $module_description;
						$plan_data['module_deliverables'] = $module_deliverables;
						
						$this->db->insert('proposal_client_plans', $plan_data);
					}
			}
			
		function cover_images($cover_id)
			{
				$this->db->select('cover_top,cover_bottom');
				$query = $this->db->from('proposal_cover');
				$this->db->where('id',$cover_id);
				$cover_links = $this->db->get()->row_array();
        		return $cover_links;
			}
			
		function cover_images_populate()
			{
				$this->db->select('id,cover_name');
				$query = $this->db->from('proposal_cover');
				$cover_links = $this->db->get()->result();
        		return $cover_links;
			}
			
		function plan_data_table($module_id,$plan_id)
			{
				$this->db->select('plan_name,plan_duration,plan_price');
				$query = $this->db->from('proposal_module_plans');
				$this->db->where('module_id',$module_id);
				$this->db->where('plan_number', $plan_id); 
				$plan_details_default = $this->db->get()->row_array();
				
				$this->db->select('module_name');
				$query = $this->db->from('proposal_module_details');
				$this->db->where('id',$module_id);
				$module_name_default = $this->db->get()->row_array();
				
				$result = array_merge($plan_details_default ,$module_name_default);
				return $result;
			}
		
		function plan_client_select()
			{
				$this->db->select('plan_name,plan_duration,plan_price');
				$query = $this->db->from('proposal_module_plans');
				$this->db->where('module_id',$module_id);
				$this->db->where('plan_number', $plan_id); 
				$plan_details_default = $this->db->get()->row_array();	
			}
		
		function plan_cover_list()
			{
				$this->db->select('id,cover_name');
				$query = $this->db->from('proposal_cover');
				$cover_list = $this->db->get()->result_array();
        		return $cover_list;
			}		
			
	}
?>